import { UserModel } from "@/api/user/UserModel";
import { EditType, FuncList } from "@/type/BaseType";
import {ref} from "vue"
import useInstance from "@/tools/useInstance";
import { deleteUserApi } from "@/api/user";
import { ElMessage } from "element-plus";
//增删改的业务操作
export default function useUser(getList:FuncList){
    const{ global } = useInstance()
    //新增、编辑弹框的ref属性
    const addRef = ref<{show:(type:string,row?:UserModel)=>void}>();
    //增
    const addBtn = ()=>{
        addRef.value?.show(EditType.ADD)
    }
    //改
    const editBtn = (row:UserModel)=>{
        addRef.value?.show(EditType.EDIT,row)
    }
    //删
    const deleteBtn = async(row:UserModel)=>{
        let flag = await global.$messageBox('确定删除该数据吗')
        if(flag){
            let result = await deleteUserApi(row.userId)
            if(result && result.code == 200){
                ElMessage.success(result.msg)
                //刷新列表
                getList()
            }
        }
    }
    return{
        addBtn,
        editBtn,
        deleteBtn,
        addRef
    }
}